
function openDetailframe(id){

	var width = api.winWidth;
	var header = $api.byId('header');
	var nav = $api.byId('oneBtnBuy');
    var navPos = $api.offset(nav);
	var headerPos = $api.offset(header);
	var height = winHeight - headerPos.h - navPos.h;
	
	$api.setStorage('d_height',height);
	
	api.openFrame({
		name:'detailFrame',
		url:'./detailFrame.html',
		rect:{
			 x: 0,
             y: headerPos.h,
             w: width,
             h: height
		},
        reload:true,
        pageParam: {shopId: id},
        customRefreshHeader: 'UIPullRefresh'
	});
}
function show(){

     var c = $api.byId('sho1p-wrap');
    $api.css(c,'display:block');
}

function changeNum(){

        var cartNum = $api.getStorage("cartNum");
        var cartNumtxt = $api.byId('cartNum');
       
        if(cartNum){
               
             if(cartNum!=0){
                $api.css(cartNumtxt,'display:block')
                $api.html(cartNumtxt,cartNum);
             }else{
                $api.css(cartNumtxt,'display:none')
                $api.html(cartNumtxt,cartNum);
             }      

        }
    }
    //刷新detail
function reshGoods(id){
	api.closeFrame({
	    name: 'detailFrame'
    });
	check(id)
}
function check(id){
		openDetailframe(id)
  	api.ajax({
        url: 'http://wap.jqmao.cn/checkNewGoods?id='+id,
        method: 'get',
        dataType: 'json'
    	}, function (ret, err) {
    	
    		if(ret){
	    		var a =$api.byId('oneBtnBuy');
	            var tpl = $api.byId('detail-template').text;
	            var tempFn = doT.template(tpl);
	            $api.html(a,tempFn(ret));
	            
				
    		}
   		})
}
var winHeight = '';
apiready = function(){
if(api.connectionType=='none'){
			error();
			  var reloading = $api.byId('reloading');
			  $api.addEvt(reloading, 'click', function(){
			  	api.closeToWin({
	                  name: 'root'
                  });
			  });
			  	return;
  	
  			}
headerstatus()
 winHeight = $(this).height();

	window.onresize=function(){
		var _height = $(this).height();
		
		var width = api.winWidth;
		var header = $api.byId('header');
		var nav = $api.byId('oneBtnBuy');
	    var navPos = $api.offset(nav);
		var headerPos = $api.offset(header);
		var height1 = winHeight - headerPos.h - navPos.h;
		//alert(height1)
		var height2 = winHeight - navPos.h;
		//alert(height2)
		//alert(winHeight)
		
		if($api.getStorage('d_height')==height1){
		
			var height = height2+4;
			//alert(111)
			
		}else{
		//alert(height1)
			var height = height1;
			//alert(222)
		}
		
		if(winHeight>_height){
			var height = height1-48;
			//alert(333)
		}
		
		$api.setStorage('d_height',height);
		api.setFrameAttr({
    name: 'detailFrame',
    rect:{
			 x: 0,
             y: headerPos.h,
             w: width,
             h: height
		},
    bounces: true,
    bgColor: '#fff'
    
});
	}
   			changeNum();
   			var id = api.pageParam.shopId;	 			
   			check(id);
   			
   			
	            	
	         
	            	
	           
            
    /*initSlide()*/ 
}
    